package net.lwf.factory;

import java.util.ArrayList;
import java.util.List;

import net.lwf.hibernate.dao.HangmanDAO;
import net.lwf.hibernate.entity.Hangman;
import net.lwf.service.LwfService;


public class HangmanData {
	
	private static HangmanData instance = null;
	private List<Hangman> data;
	private List<Hangman> words;
	private List<Hangman> quotes;

	
	private HangmanData() {
		this.init();
	}
	
	public List<Hangman> getWords() {
		return words;
	}
	
	public List<Hangman> getQuotes() {
		return quotes;
	}

	public synchronized final static HangmanData getInstance(){
		if (instance == null) {
			instance = new HangmanData();
		}
		return instance;
	}
	
	private void init() {
		if(LwfService.isMock()) {
			data = this.getTestData();
		}
		else {
			data = new HangmanDAO().getData();
		}
		
		words = new ArrayList<Hangman>();
		quotes = new ArrayList<Hangman>();
		for(Hangman record: data) {
			if(record.getType().equalsIgnoreCase("word")) {
				words.add(record);
			}
			else {
				quotes.add(record);
			}
		}
	}
	
	private List<Hangman> getTestData() {
		List<Hangman> data = new ArrayList<Hangman>();
		data.addAll(this.getTestWords());
		data.addAll(this.getTestQuotes());
		return data;
	}
	
	private List<Hangman> getTestWords() {
		List<Hangman> words = new ArrayList<Hangman>();
		Hangman man = new Hangman();
		man.setHint("Hint one");
		man.setAnswer("Word one");
		man.setType("word");
		words.add(man);
		man = new Hangman();
		man.setHint("Hint two");
		man.setAnswer("Word two");
		man.setType("word");
		words.add(man);
		man = new Hangman();
		man.setHint("Hint three");
		man.setAnswer("Word three");
		man.setType("word");
		words.add(man);
		man = new Hangman();
		man.setHint("Hint four");
		man.setAnswer("Word four");
		man.setType("word");
		words.add(man);
		man = new Hangman();
		man.setHint("Hint five");
		man.setAnswer("Word five");
		man.setType("word");
		words.add(man);
		man = new Hangman();
		man.setHint("Hint six");
		man.setAnswer("Word six");
		man.setType("word");
		words.add(man);
		man = new Hangman();
		man.setHint("Hint seven");
		man.setAnswer("Word seven");
		man.setType("word");
		words.add(man);
		man = new Hangman();
		man.setHint("Hint eight");
		man.setAnswer("Word eight");
		man.setType("word");
		words.add(man);

		return words;

	}

	private List<Hangman> getTestQuotes() {
		List<Hangman> quotes = new ArrayList<Hangman>();
		Hangman man = new Hangman();
		man.setHint("Hint one");
		man.setAnswer("Quote one");
		man.setType("quote");
		quotes.add(man);
		man = new Hangman();
		man.setHint("Hint two");
		man.setAnswer("Quote two");
		man.setType("quote");
		quotes.add(man);
		man = new Hangman();
		man.setHint("Hint three");
		man.setAnswer("Quote three");
		man.setType("quote");
		quotes.add(man);
		man = new Hangman();
		man.setHint("Hint four");
		man.setAnswer("Quote four");
		man.setType("quote");
		quotes.add(man);
		man = new Hangman();
		man.setHint("Hint five");
		man.setAnswer("Quote five");
		man.setType("quote");
		quotes.add(man);
		man = new Hangman();
		man.setHint("Hint six");
		man.setAnswer("Quote six");
		man.setType("quote");
		quotes.add(man);
		man = new Hangman();
		man.setHint("Hint seven");
		man.setAnswer("Quote seven");
		man.setType("quote");
		quotes.add(man);
		man = new Hangman();
		man.setHint("Hint eight");
		man.setAnswer("Quote eight");
		man.setType("quote");
		quotes.add(man);

		return quotes;

	}

}
